home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z11.ADF / LOGO / LOGOSOURCE / splithelp.c < prev    next >
C/C++ Source or Header  |  1987-07-01  |  1KB  |  68 lines

  1.  
  2. /*
  3.  * splithelp.c -- turn nroff output of logoman into help files.
  4.  */
  5.  
  6. extern char *index();
  7.  
  8. #define SPACES    "                     "
  9.  
  10.  
  11. #include <stdio.h>
  12.  
  13. main(argc,argv)
  14. char **argv;
  15. {
  16.     FILE *ip, *op;
  17.     int writing = 0;    /* nonzero when writing a file */
  18.     int empty = 0;        /* nonzero after an empty line */
  19.     register char *cp;
  20.     char line[100];
  21.     char primitive[50];
  22.  
  23.     if ((ip = fopen(argv[1],"r")) == NULL) {
  24.         printf("Splithelp: Can't read input.\n");
  25.         exit(1);
  26.     }
  27.  
  28.     while (fgets(line,100,ip)) {
  29.         cp = index(line, '-');
  30.         if (cp && *(cp - 1) == ' ' && *(cp + 1) == ' ') {
  31.  
  32.             empty = 0;
  33.             if (writing)
  34.                 fclose(op);
  35.  
  36.             sscanf(line,"%s",primitive);
  37.  
  38.             if ((op = fopen(primitive,"w")) == NULL) {
  39.                 printf("Splithelp: Can't write output <%s>.\n", primitive);
  40.                 exit(1);
  41.             }
  42.  
  43.             fprintf(op,"%s",line);
  44.             writing++;
  45.         } else if (line[0] == '\n' || strncmp(line,SPACES,16) == 0) {
  46.             empty++;
  47.         } else if (writing && line[0]==' ') {
  48.             sscanf(line,"%s",primitive);
  49.             if (empty && (index(primitive, '_') ||
  50.                           primitive[strlen(primitive)-1] == '.')) {
  51.                 fclose(op);
  52.                 writing = 0;
  53.             }
  54.             else {
  55.                 if (empty)
  56.                     fprintf(op,"\n");
  57.                 empty = 0;
  58.                 fprintf(op,"%s",line);
  59.             }
  60.         } else if (writing) {
  61.             fclose(op);
  62.             writing = 0;
  63.         }
  64.     }
  65.     if (writing) fclose(op);
  66. }
  67.  
  68.